#include "level2.h"

Level2::Level2(QWidget *parent)
    : LevelScene(QPixmap(RESOURCE_DIR + "/Rose_Present_Map.png"),QImage(RESOURCE_DIR + "/Rose_Present_Mask.png"), parent)
{
    buildingImage = new GameBackground(QPixmap(RESOURCE_DIR + "/Rose_Present_Buildings.png"),mainScene);
    buildingImage->setZValue(1);

    river = new River(QPixmap(RESOURCE_DIR + "/1water1.png"),mainScene,this);
    QObject::connect(river,SIGNAL(clicked()),this,SLOT(riverClicked()));
    QObject::connect(river,SIGNAL(hoverChanged(bool)),this,SLOT(riverHoverChanged(bool)));

    // Add the tools
    quarantineTool = addTool(15,QString("Quarantien (Place road block)"),RESOURCE_DIR + "/buttons/Dean_RoadBlock.png");
    sterilizationTool = addTool(5,QString("Sterilize building"),RESOURCE_DIR + "/buttons/Dean_Sterilize.png");
    cleanWaterTool = addTool(300,QString("Clean city water supply"),RESOURCE_DIR + "/buttons/Dean_CleanWater.png");
    coughSyrupTool = addTool(5,QString("Give people in a building cough syrup"),RESOURCE_DIR + "/buttons/Dean_CoughSyrup.png");
    antiViralsTool = addTool(10,QString("Give building Antivirals"),RESOURCE_DIR + "/buttons/Dean_AntiVir.png");
    gammaGlobulinTool = addTool(10,QString("Treat building with Gamma Globulins"),RESOURCE_DIR + "/buttons/Dean_GammaGlobulians.png");
    vacceneTool = addTool(30,QString("Vaccinate Building"),RESOURCE_DIR + "/buttons/Dean_Vaccine.png");
    interferonTool = addTool(10,QString("Treat building with Interferons"),RESOURCE_DIR + "/buttons/Dean_Interferon.png");

    // Add one story houses
    QPointF house1Info[64][2] = {{QPointF(220,895),QPointF(23,91)},
                                 {QPointF(220+52,895),QPointF(31,91)},
                                 {QPointF(220,946),QPointF(24,98)},
                                 {QPointF(220+52,946),QPointF(29,98)},

                                 {QPointF(344,895),QPointF(35,91)},
                                 {QPointF(344+52,895),QPointF(43,91)},
                                 {QPointF(344,946),QPointF(37,98)},
                                 {QPointF(344+52,946),QPointF(42,98)},

                                 {QPointF(14,1020),QPointF(5,104)},
                                 {QPointF(14,1020+51),QPointF(4,111)},

                                 {QPointF(96,1020),QPointF(10,104)},
                                 {QPointF(96+52,1020),QPointF(18,104)},
                                 {QPointF(96,1020+51),QPointF(12,111)},
                                 {QPointF(96+52,1020+51),QPointF(17,111)},

                                 {QPointF(220,1020),QPointF(23,104)},
                                 {QPointF(220+52,1020),QPointF(31,104)},
                                 {QPointF(220,1020+51),QPointF(25,111)},
                                 {QPointF(220+52,1020+51),QPointF(30,111)},

                                 {QPointF(344,1020),QPointF(35,104)},
                                 {QPointF(344+52,1020),QPointF(43,104)},
                                 {QPointF(344,1020+51),QPointF(37,111)},
                                 {QPointF(344+52,1020+51),QPointF(42,111)},

                                 {QPointF(14,1144),QPointF(5,116)},
                                 {QPointF(14,1144+51),QPointF(4,123)},

                                 {QPointF(96,1144),QPointF(10,116)},
                                 {QPointF(96+52,1144),QPointF(18,116)},
                                 {QPointF(96,1144+51),QPointF(12,123)},
                                 {QPointF(96+52,1144+51),QPointF(17,123)},

                                 {QPointF(220,1144),QPointF(23,116)},
                                 {QPointF(220+52,1144),QPointF(31,116)},
                                 {QPointF(220,1144+51),QPointF(25,123)},
                                 {QPointF(220+52,1144+51),QPointF(30,123)},

                                 {QPointF(1922,346),QPointF(193,37)},
                                 {QPointF(1922,346+51),QPointF(194,43)},
                                 {QPointF(1922,478),QPointF(193,50)},
                                 {QPointF(1922,478+60),QPointF(194,58)},
                                 {QPointF(1922,628),QPointF(193,65)},
                                 {QPointF(1922,628+60),QPointF(194,73)},
                                 {QPointF(1922,778),QPointF(193,80)},
                                 {QPointF(1922,778+60),QPointF(195,88)},
                                 {QPointF(1922,928),QPointF(193,95)},
                                 {QPointF(1922,928+60),QPointF(195,103)},
                                 {QPointF(1922,1078),QPointF(193,110)},
                                 {QPointF(1922,1078+60),QPointF(194,118)},

                                 {QPointF(1749,928),QPointF(176,95)},
                                 {QPointF(1749,928+60),QPointF(177,103)},
                                 {QPointF(1749+56,928),QPointF(184,95)},
                                 {QPointF(1749+56,928+60),QPointF(183,103)},

                                 {QPointF(1621,928),QPointF(163,95)},
                                 {QPointF(1621,928+60),QPointF(164,103)},
                                 {QPointF(1621+51,928),QPointF(171,95)},
                                 {QPointF(1621+51,928+60),QPointF(170,103)},

                                 {QPointF(1749,1078),QPointF(176,110)},
                                 {QPointF(1749,1078+60),QPointF(177,118)},
                                 {QPointF(1749+56,1078),QPointF(184,110)},
                                 {QPointF(1749+56,1078+60),QPointF(183,118)},

                                 {QPointF(1621,1078),QPointF(163,110)},
                                 {QPointF(1621,1078+60),QPointF(164,118)},
                                 {QPointF(1621+51,1078),QPointF(171,110)},
                                 {QPointF(1621+51,1078+60),QPointF(170,118)},

                                 {QPointF(1496,1078),QPointF(151,110)},
                                 {QPointF(1496,1078+60),QPointF(152,118)},
                                 {QPointF(1496+51,1078),QPointF(158,110)},
                                 {QPointF(1496+51,1078+60),QPointF(157,118)},
                               };

    for (unsigned int index = 0; index < (sizeof(house1Info)/(sizeof(*house1Info[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 4);
        addBuilding(QPoint(house1Info[index][1].toPoint()),QPointF(house1Info[index][0]),QPixmap(RESOURCE_DIR + "/buildings/Rose_1home" + buildingColor + ".png"));
    }

    // Add two story houses
    QPointF house2Info[24][2] = {{QPointF(776,245),QPointF(80,31)},
                                 {QPointF(776+65,245),QPointF(86,31)},
                                 {QPointF(926,245),QPointF(95,31)},
                                 {QPointF(926+65,245),QPointF(101,31)},
                                 {QPointF(1076,245),QPointF(110,31)},
                                 {QPointF(1076+65,245),QPointF(116,31)},
                                 {QPointF(1373,371),QPointF(139,43)},
                                 {QPointF(1373+50,371),QPointF(144,43)},
                                 {QPointF(1498,371),QPointF(152,43)},
                                 {QPointF(1498+50,371),QPointF(157,43)},
                                 {QPointF(1749,371),QPointF(177,43)},
                                 {QPointF(1749+55,371),QPointF(182,43)},
                                 {QPointF(1749,520),QPointF(177,58)},
                                 {QPointF(1749+55,520),QPointF(182,58)},
                                 {QPointF(1623,520),QPointF(165,58)},
                                 {QPointF(1623+50,520),QPointF(170,58)},
                                 {QPointF(1749,822),QPointF(177,88)},
                                 {QPointF(1749+55,822),QPointF(183,88)},
                                 {QPointF(1623,822),QPointF(165,88)},
                                 {QPointF(1623+50,822),QPointF(169,88)},
                                 {QPointF(1370,970),QPointF(139,103)},
                                 {QPointF(1370+50,970),QPointF(144,103)},
                                 {QPointF(1370,1120),QPointF(139,118)},
                                 {QPointF(1370+50,1120),QPointF(144,118)},
                                };

    for (unsigned int index = 0; index < (sizeof(house2Info)/(sizeof(*house2Info[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 4);
        addBuilding(QPoint(house2Info[index][1].toPoint()),QPointF(house2Info[index][0]),QPixmap(RESOURCE_DIR + "/buildings/Rose_2home" + buildingColor + ".png"));
    }

    // Add three story house
    char buildingColor = '1' + (rand() % 4);
    addBuilding(QPoint(131,30),QPointF(1224,198),QPixmap(RESOURCE_DIR + "/buildings/Rose_3home" + buildingColor + ".png"));

    // Add office buildings
    QPointF officeInfo[17][2] = {{QPointF(767,470),QPointF(80,58)},
                                 {QPointF(767+65,470),QPointF(86,58)},
                                 {QPointF(917,470),QPointF(95,58)},
                                 {QPointF(917+65,470),QPointF(101,58)},
                                 {QPointF(767,620),QPointF(80,73)},
                                 {QPointF(767+65,620),QPointF(86,73)},
                                 {QPointF(917,620),QPointF(95,73)},
                                 {QPointF(917+65,620),QPointF(101,73)},
                                 {QPointF(1066,470),QPointF(110,58)},
                                 {QPointF(1066+65,470),QPointF(116,58)},
                                 {QPointF(1217,470),QPointF(125,58)},
                                 {QPointF(1217+65,470),QPointF(131,58)},
                                 {QPointF(1380,470),QPointF(141,58)},
                                 {QPointF(1402,620),QPointF(143,73)},
                                 {QPointF(1367,770),QPointF(140,88)},
                                 {QPointF(1216,1070),QPointF(125,118)},
                                 {QPointF(1216+65,1070),QPointF(131,118)},
                                };

    for (unsigned int index = 0; index < (sizeof(officeInfo)/(sizeof(*officeInfo[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 3);
        addBuilding(QPoint(officeInfo[index][1].toPoint()),QPointF(officeInfo[index][0]),QPixmap(RESOURCE_DIR + "/buildings/1Skyscraper" + buildingColor + ".png"));
    }

    // Add stores
    QPointF storesInfo[32][2] = {{QPointF(766,350),QPointF(79,38)},
                                 {QPointF(766,402),QPointF(79,43)},
                                 {QPointF(834,350),QPointF(87,38)},
                                 {QPointF(834,402),QPointF(86,43)},

                                 {QPointF(916,350),QPointF(94,38)},
                                 {QPointF(916,402),QPointF(94,43)},
                                 {QPointF(984,350),QPointF(102,38)},
                                 {QPointF(984,402),QPointF(101,43)},

                                 {QPointF(1066,350),QPointF(109,38)},
                                 {QPointF(1066,402),QPointF(109,43)},
                                 {QPointF(1134,350),QPointF(117,38)},
                                 {QPointF(1134,402),QPointF(116,43)},

                                 {QPointF(1216,350),QPointF(124,38)},
                                 {QPointF(1216,402),QPointF(124,43)},
                                 {QPointF(1284,350),QPointF(132,38)},
                                 {QPointF(1284,402),QPointF(131,43)},

                                 {QPointF(1638,633),QPointF(166,66)},
                                 {QPointF(1638,695),QPointF(166,72)},

                                 {QPointF(1514,783),QPointF(154,81)},
                                 {QPointF(1514,844),QPointF(154,87)},

                                 {QPointF(765,928),QPointF(79,95)},
                                 {QPointF(765,996),QPointF(79,102)},
                                 {QPointF(834,928),QPointF(86,95)},
                                 {QPointF(834,996),QPointF(86,102)},

                                 {QPointF(915,1078),QPointF(94,110)},
                                 {QPointF(984,1078),QPointF(101,110)},
                                 {QPointF(915,1146),QPointF(94,117)},
                                 {QPointF(984,1146),QPointF(101,117)},
                                 
                                 {QPointF(1065,1078),QPointF(109,110)},
                                 {QPointF(1134,1078),QPointF(116,110)},
                                 {QPointF(1065,1146),QPointF(109,117)},
                                 {QPointF(1134,1146),QPointF(116,117)},
                                };

    for (unsigned int index = 0; index < (sizeof(storesInfo)/(sizeof(*storesInfo[0])*2)); index++)
    {
        char buildingColor = '1' + (rand() % 3);
        addBuilding(QPoint(storesInfo[index][1].toPoint()),QPointF(storesInfo[index][0]),QPixmap(RESOURCE_DIR + "/buildings/2Store" + buildingColor + ".png"));
    }

    // Add other buildings
    addBuilding(QPoint(88,85),QPointF(775,785),QPixmap(RESOURCE_DIR + "/buildings/2PostOffice.png"));
    addBuilding(QPoint(93,102),QPointF(920,935),QPixmap(RESOURCE_DIR + "/buildings/1FireStation.png"));
    addBuilding(QPoint(113,72),QPointF(1071,618),QPixmap(RESOURCE_DIR + "/buildings/2CityHall1.png"));
    addBuilding(QPoint(113,87),QPointF(1069,766),QPixmap(RESOURCE_DIR + "/buildings/2CourtHouse1.png"));
    addBuilding(QPoint(112,103),QPointF(1069,917),QPixmap(RESOURCE_DIR + "/buildings/2policestation1.png"));
    addBuilding(QPoint(125,70),QPointF(1219,616.5),QPixmap(RESOURCE_DIR + "/buildings/1school1.png"));
    addBuilding(QPoint(156,98),QPointF(1498,925),QPixmap(RESOURCE_DIR + "/buildings/1school2.png"));
    addBuilding(QPoint(16,95),QPointF(98,897),QPixmap(RESOURCE_DIR + "/buildings/1school2.png"));
    addBuilding(QPoint(181,72),QPointF(1743,620),QPixmap(RESOURCE_DIR + "/buildings/1hospital1.png"));
    addBuilding(QPoint(36,119),QPointF(348,1148),QPixmap(RESOURCE_DIR + "/buildings/3policestation1.png"));
    addBuilding(QPoint(43,121),QPointF(395,1156),QPixmap(RESOURCE_DIR + "/buildings/2FireStation.png"));
    addBuilding(QPoint(167,41),QPointF(1624,356),QPixmap(RESOURCE_DIR + "/buildings/3Bank1.png"));
    addBuilding(QPoint(154,55),QPointF(1499,482),QPixmap(RESOURCE_DIR + "/buildings/1Mall1-small.png"));
    addBuilding(QPoint(154,71),QPointF(1499,632),QPixmap(RESOURCE_DIR + "/buildings/1Mall1-small.png"));
    addBuilding(QPoint(128,84),QPointF(1223,780),QPixmap(RESOURCE_DIR + "/buildings/1library1.png"));
    addBuilding(QPoint(128,102),QPointF(1226,923),QPixmap(RESOURCE_DIR + "/buildings/2Bank1.png"));
    addBuilding(QPoint(83,117),QPointF(771,1071),QPixmap(RESOURCE_DIR + "/buildings/1Mall1.png"));

    QString convertString;

    for (int count = 0; count<700; count ++)
    {
        convertString.setNum((rand()%12) + 1);
        addPerson(QPixmap(RESOURCE_DIR + "/people/Dean_Person" + convertString + ".png"),buildings.at(rand() % buildings.length()));
    }
    for (int count = 0; count<30; count ++)
    {
        convertString.setNum((rand()%12) + 1);
        int r = rand() % 3;
        if (r == 0)
            addPerson(QPixmap(RESOURCE_DIR + "/people/Dean_Person" + convertString + ".png"),buildings.at(118));
        else if (r == 1)
            addPerson(QPixmap(RESOURCE_DIR + "/people/Dean_Person" + convertString + ".png"),buildings.at(119));
        else
            addPerson(QPixmap(RESOURCE_DIR + "/people/Dean_Person" + convertString + ".png"),buildings.at(154));
        people.last()->virus = new Virus(525,225,250,0,people.last());
    }

    healthyCountThreshold = people.length() - 175;
    healthyTimeThreshold = QTime(0,2,0,0);

    maxPeopleOnStreet = 40;
    currentLevel = levelScene2;
}
